<template>
	<view class="columnbox wdh-100 content">
		<view v-for="(item,index) in list" :key='index' class="one-box columnbox" @click="chooseTem(item)">
			<view class="wdh-100 tem-name">{{item.name}}
			</view>
			<view class="wdh-100 tem-desc">辨病：{{item.bianbing}}</view>
			<view class="wdh-100 tem-desc">辨症：{{item.bianzheng}}</view>
			<view class="wdh-100 tem-desc">剂型：{{item.jixing}}</view>
			<!-- <view class="wdh-100 tem-desc rowbox jus als">
				<view style="width: fit-content;white-space: nowrap;">药品信息：</view>
				<text>
					<text style="margin-right: 20rpx;" v-for="(items,indexs) in item.Prescriptionxydrug" :key='indexs'>
						{{items.medicine}}*{{items.num}}<text v-if="item.inventory==0">(商品不足)</text>
					</text>
				</text>
			</view> -->
			<view class="rowbox wdh-100 tem-list">
				<view class="rowbox del-btn" style="margin-right: 20rpx;" @click.stop="showEwm(item)">二维码</view>
				<view class="rowbox del-btn def-bgcol" style="margin-right: 20rpx;color: #fff;"
					@click.stop="updateInfo(item)">修改</view>
				<view class="rowbox del-btn" style="color: #fc1c15;" @click.stop="deletInfo(item)">删除</view>
			</view>
		</view>
		<view style="width: 100%;height: 200rpx;"></view>
		<view class="rowbox wdh-100 bottom-box">
			<view @click="addTem" class="rowbox send-btn wdh-100">新建处方模版</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageNo: 1,
				list: [],
				totalCount: 0,
				refreshflag: false,
				type: ''
			};
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
			}
			this.getList()
		},
		onReachBottom() {
			if (this.list.length < this.totalCount) {
				this.pageNo++
				this.getList()
			}
		},
		onShow() {
			if (this.refreshflag) {
				this.refreshflag = false
				this.pageNo = 1
				this.list = []
				this.getList()
			}
		},
		methods: {
			updateInfo(v) {
				uni.navigateTo({
					url: '/packageA/zhongyaoChufang/add?id=' + v.id
				})
			},
			// 展示二维码
			showEwm(v) {
				console.log(v.erweima)
				uni.previewImage({
					urls: [v.erweima]
				})
			},
			chooseTem(v) {
				if (this.type == '' && v.kaifang == 1) {
					let pages = getCurrentPages(); //获取所有页面栈实例列表
					let nowPage = pages[pages.length - 1]; //当前页页面实例
					let prevPage = pages[pages.length - 2]; //上一页页面实例
					prevPage.$vm.infoList = v.Prescriptionxydrug
					prevPage.$vm.bianbing = v.jibing
					uni.navigateBack()
				}
			},
			deletInfo(v) {
				uni.showModal({
					title: '是否确认删除',
					success: (res) => {
						if (res.confirm) {
							this.$req.post('/doctor/prescriptionmbdel', {
								id: v.id
							}).then(res => {
								this.pageNo = 1
								this.list = []
								this.getList()
							})
						}
					}
				})
			},
			getList() {
				this.$req.post('/doctor/prescriptionmblist', {
					doctorid: uni.getStorageSync('uid'),
					pageNo: this.pageNo,
					pageSize: 20
				}).then(res => {
					this.list = this.list.concat(res.data.data.data)
					this.totalCount = res.data.data.totalCount
				})
			},
			addTem() {
				uni.navigateTo({
					url: './add'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background: #F5F8FB;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.one-box {
		width: 710rpx;
		background: #fff;
		border-radius: 20rpx;
		padding: 20rpx 20rpx;
		margin: 10rpx 0;

		.tem-name {
			font-size: 28rpx;
			font-weight: bold;
		}

		.tem-desc {
			margin-top: 20rpx;
			font-size: 24rpx;
			color: #96949e;
		}

		.tem-list {
			margin-top: 10rpx;
			justify-content: flex-end;
			font-size: 24rpx;
		}

		.choose-btn {
			margin-left: 20rpx;
			color: #fff;
			width: 100rpx;
			height: 50rpx;
			border-radius: 10rpx;
		}

		.del-btn {
			padding: 0 20rpx;
			height: 50rpx;
			border-radius: 10rpx;
			border: #e6e9eb solid 1px;
			color: #717171;
		}
	}
</style>